#[derive(Debug)]
//struct Interface<'b, 'a: 'b> {
struct Interface<'b, 'a> where 'a:'b {
    //a的生命周期要大于b
    manager: &'b mut Manager<'a>
}

//impl<'b, 'a:'b> Interface<'b, 'a> {
    //这里不涉及生命周期引用可以改写如下
impl Interface<'_, '_> {
    pub fn noop(self) {
        println!("interface consumed <{}>",self.manager.text);
    }
}

#[derive(Debug)]
struct Manager<'a> {
    text: &'a str
}

struct List<'a> {
    manager: Manager<'a>,
}

impl<'a> List<'a> {
    pub fn get_interface<'b>(&'b mut self) -> Interface<'b, 'a>
        where 'a: 'b {
            Interface {
                manager: &mut self.manager
            }
    }
}

fn use_list(list: &List) {
    println!("{}", list.manager.text);
}

fn main(){
    let mut list = List {
        manager: Manager {
            text: "hello"
        }
    };
    list.get_interface().noop(); //noop调用完归还list.manager的所有权
    println!("Interface should be dropped here and the borrow released");
    use_list(&list)
}
